<template>
  <div class="new_auction_Income_detail">
    <c-title :hide="false" :text="pageTitle"></c-title>
    <div class="account_management_top">
      <div class="account_management_top_member" v-if="info.member">
        <div class="uimg">
          <img :src="info.member.avatar" alt="" />
        </div>
        <div class="account_management_top_member_r">
          <div class="name">{{ info.member.nickname }}</div>
          <div class="level">{{ info.member.level_name }}</div>
        </div>
      </div>
    </div>
    <div class="detailBox">
      <div v-if="$route.name != 'new_auction_supplier'" class="WithdrawBox" @click="towithdraw">
        <div class="WithdrawBox_l">可提现：¥{{ info.can_withdraw_income }}</div>
        <div class="WithdrawBox_r">去提现<van-icon name="arrow" /></div>
      </div>
      <div class="gridBox">
        <van-grid :column-num="2" v-if="$route.name != 'new_auction_supplier'">
          <van-grid-item>
            <template #default>
              <span class="detail_t">{{ $i18n.t("money") }}{{ info.sum_income }}</span>
              <span class="detail_b">收入总额</span>
            </template>
          </van-grid-item>
          <van-grid-item>
            <template #default>
              <span class="detail_t">{{ $i18n.t("money") }}{{ info.settle_income }}</span>
              <span class="detail_b">已结算收入</span>
            </template>
          </van-grid-item>
          <van-grid-item>
            <template #default>
              <span class="detail_t">{{ $i18n.t("money") }}{{ info.unsettle_income }}</span>
              <span class="detail_b">未结算收入</span>
            </template>
          </van-grid-item>
          <van-grid-item>
            <template #default>
              <span class="detail_t">{{ $i18n.t("money") }}{{ info.point }}</span>
              <span class="detail_b">积分</span>
            </template>
          </van-grid-item>
        </van-grid>
        <van-grid :column-num="3" v-else>
          <van-grid-item>
            <template #default>
              <span class="detail_t">{{ $i18n.t("money") }}{{ info.sum_income }}</span>
              <span class="detail_b">收入总额</span>
            </template>
          </van-grid-item>
          <van-grid-item>
            <template #default>
              <span class="detail_t">{{ $i18n.t("money") }}{{ info.settle_income }}</span>
              <span class="detail_b">已结算收入</span>
            </template>
          </van-grid-item>
          <van-grid-item>
            <template #default>
              <span class="detail_t">{{ $i18n.t("money") }}{{ info.unsettle_income }}</span>
              <span class="detail_b">未结算收入</span>
            </template>
          </van-grid-item>
        </van-grid>
      </div>
    </div>
    <van-tabs v-model="active" background="#F7F7F7" line-width="15px" title-active-color="#F15353" @change="tabChange">
      <van-tab title="全部" name="0"></van-tab>
      <van-tab title="已结算" name="2"></van-tab>
      <van-tab title="未结算" name="1"></van-tab>
    </van-tabs>
    <div class="list">
      <div class="lis" v-for="(item, index) in list" :key="index">
        <div class="lis_t">
          <div class="lis_t_t">
            <div class="lis_t_l">{{ item.id_desc }}</div>
            <div class="lis_t_r">{{ item.type_name }}{{ item.reward_amount }}</div>
          </div>
          <div class="lis_t_b">
            <div class="lis_b_l">{{ item.created_at }}</div>
            <div class="lis_b_r">{{ item.status_name }}</div>
          </div>
        </div>
        <div class="list_b" v-if="$route.name != 'new_auction_Profit_detail'">
          <div class="list_b_l" v-if="item.has_one_buyer">
            <div class="list_b_l_img">
              <img :src="item.has_one_buyer.avatar" alt="" />
            </div>
            <span class="name">{{ item.has_one_buyer.nickname }}</span>
          </div>
          <div class="list_b_r" v-if="item.has_one_activity">{{ item.has_one_activity.name }}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { scrollMixin } from "utils/mixin";
export default {
  mixins: [scrollMixin],
  data() {
    return {
      active: 0,
      pageTitle: "",
      info: [],
      list: [],

      isLoadMore: true,
      page: 1,
      total_page: 0
    };
  },
  activated() {
    this.pageTitle = this.$route.meta.title;
    if (this.$route.name == "new_auction_supplier") {
      let plugin_setting = localStorage.getItem("plugin_setting") ? JSON.parse(localStorage.getItem("plugin_setting")) : "";
      let plugin_name = plugin_setting.new_auction.plugin_name;
      this.fun.setWXTitle(`${plugin_name}供应商奖励`);
      this.pageTitle = `${plugin_name}供应商奖励`;
    }
    this.getData();
  },
  methods: {
    init() {
      this.list = [];
      this.page = 1;
      this.total_page = 0;
      this.isLoadMore = true;
    },
    towithdraw() {
      this.$router.push(this.fun.getUrl("new_auction_withdraw", { tag: "income" }));
    },
    tabChange() {
      this.init();
      let json = {};
      if (this.$route.name == "new_auction_Profit_detail") {
        json.source = 1;
      } else if (this.$route.name == "new_auction_Income_detail") {
        json.source = 2;
      } else {
        json.source = 3;
      }
      this.getList(json);
    },
    async getData() {
      // new_auction_Profit_detail 盈利,会员自己
      // new_auction_Income_detail 上级
      // new_auction_supplier 供应商
      let urlstr = "plugin.new-auction.frontend.reward.summary";
      let json = { source: "" };
      if (this.$route.name == "new_auction_Profit_detail") {
        json.source = 1;
      } else if (this.$route.name == "new_auction_Income_detail") {
        json.source = 2;
      } else {
        json.source = 3;
      }
      let { data, msg, result } = await $http.post(urlstr, json, "");
      if (result) {
        this.info = data;
        this.getList(json);
      } else {
        this.$toast(msg);
      }
    },
    async getMoreData() {
      if (!this.isLoadMore) return;
      this.isLoadMore = false;
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page += 1;
        let json = {
          page: this.page,
          status: this.active
        };
        if (this.$route.name == "new_auction_Profit_detail") {
          json.source = 1;
        } else if (this.$route.name == "new_auction_Income_detail") {
          json.source = 2;
        } else {
          json.source = 3;
        }
        let urlstr = "plugin.new-auction.frontend.reward.index";
        let { data, msg, result } = await $http.post(urlstr, json, "");
        this.isLoadMore = true;
        if (result) {
          this.list = this.list.concat(data.data);
        } else {
          this.page = this.page - 1;
          this.isLoadMore = false;
          this.$toast(msg);
        }
      }
    },
    async getList(json) {
      json.status = this.active;
      let { data, msg, result } = await $http.post("plugin.new-auction.frontend.reward.index", json, "");
      if (result) {
        this.list = data.data;
        this.isLoadMore = true;
        this.total_page = data.last_page;
      } else {
        this.$toast(msg);
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.account_management_top {
  height: 8.5rem;
  background: linear-gradient(180deg, #f15353 0%, #f5f5f5 100%);
  padding: 0.88rem 1.06rem;
  box-sizing: border-box;
  .account_management_top_member {
    display: flex;
    .uimg {
      width: 3.44rem;
      height: 3.44rem;
      border-radius: 50%;
      flex-shrink: 0;
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
      }
    }
    .account_management_top_member_r {
      margin-left: 0.53rem;
      display: flex;
      flex-direction: column;
      justify-content: flex-end;
      .name {
        font-size: 1rem;
        color: #ffffff;
        font-weight: bold;
        line-height: 1rem;
        margin-bottom: 0.3rem;
      }
      .level {
        font-size: 0.69rem;
        color: #ffffff;
        line-height: 0.7rem;
        padding: 0.28rem 0.63rem;
        border-radius: 0.63rem;
        background: #d94b4b;
      }
    }
  }
}
.gridBox {
  // margin: -2.9rem 0.75rem 0 0.75rem;
  background: #ffffff;
  border-radius: 0.5rem;
  overflow: hidden;
  .detail_t {
    font-size: 0.94rem;
    color: #00001c;
    font-weight: bold;
    line-height: 0.94rem;
  }
  .detail_b {
    font-size: 0.75rem;
    color: #6e6e79;
    line-height: 0.8rem;
    margin-top: 0.44rem;
  }
}
.list {
  margin: 0.63rem 0.75rem 0 0.75rem;
  padding-bottom: 1rem;
  .lis {
    padding: 0.94rem 0.75rem;
    background: #ffffff;
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    .list_b {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding-top: 0.5rem;
      border-top: 1px solid #f0f0f1;
      margin-top: 0.81rem;
      .list_b_r {
        font-size: 0.81rem;
        color: #818181;
      }
      .list_b_l {
        flex: 1;
        display: flex;
        align-items: center;
        .list_b_l_img {
          width: 1.5rem;
          height: 1.5rem;
          margin-right: 0.28rem;
          border-radius: 50%;
          img {
            width: 100%;
            height: 100%;
            border-radius: 50%;
          }
        }
        .name {
          font-size: 0.81rem;
          color: #818181;
        }
      }
    }
    .lis_t {
      .lis_t_t,
      .lis_t_b {
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
      .lis_t_b {
        margin-top: 0.4rem;
      }
      .lis_t_l {
        font-weight: 500;
        font-size: 0.94rem;
      }
      .lis_t_r {
        font-weight: 500;
        font-size: 0.88rem;
      }
      .lis_b_l {
        font-size: 0.69rem;
        color: #686868;
      }
      .lis_b_r {
        font-size: 0.69rem;
        color: #686868;
      }
    }
  }
}
.detailBox {
  margin: -2.9rem 0.75rem 0 0.75rem;
  .WithdrawBox {
    height: 3rem;
    background: #ffffff;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    padding: 0 0.75rem;
    box-sizing: border-box;
    justify-content: space-between;
    margin-bottom: 0.63rem;
    .WithdrawBox_l {
      font-weight: 500;
      font-size: 0.88rem;
    }
    .WithdrawBox_r {
      font-weight: 500;
      font-size: 0.88rem;
      color: #f15353;
      display: flex;
      align-items: center;
      .van-icon {
        margin-left: 0.4rem;
      }
    }
  }
}
</style>
